import lang from 'element-plus/lib/locale/lang/zh-cn'
import 'dayjs/locale/zh-cn'
import {
  locale,
  ElButton,
  ElCard,
  ElLoading,
  ElContainer,
  ElHeader,
  ElAside,
  ElMain,
  ElMenu,
  ElMenuItem,
  ElMenuItemGroup,
  ElSubmenu,
  ElAvatar,
  ElTooltip,
  ElBreadcrumb,
  ElBreadcrumbItem,
  ElDropdown,
  ElDropdownItem,
  ElDropdownMenu,
} from 'element-plus';

import 'element-plus/packages/theme-chalk/src/base.scss'
import 'element-plus/lib/theme-chalk/index.css';

const components = [
  ElContainer,
  ElHeader,
  ElAside,
  ElMain,
  ElButton,
  ElCard,
  ElMenu,
  ElMenuItem,
  ElMenuItemGroup,
  ElSubmenu,
  ElAvatar,
  ElTooltip,
  ElBreadcrumb,
  ElBreadcrumbItem,
  ElDropdown,
  ElDropdownItem,
  ElDropdownMenu,

]

const plugins = [
  ElLoading
]

const loadElementPlus = (app: any, options = {}) => {
  // 引入语言，不引入默认英语
  locale(lang);
  // 全局注册组件
  components.forEach(component => {
    app.component(component.name, component)
  })

  plugins.forEach(plugin => {
    app.use(plugin)
  })

  // 设置全局option，默认 {}
  app.config.globalProperties.$ELEMENT = options
}

export default loadElementPlus
